/**
 * 
 */
package com.firebird.oms.service.sm.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.firebird.oms.dao.sm.TismStaffDao;
import com.firebird.oms.dao.sm.TismWorkerDao;
import com.firebird.oms.domain.sm.TismStaff;
import com.firebird.oms.domain.sm.TismWorker;
import com.firebird.oms.service.sm.StaffService;

/**
 * @author qiuxj
 * @date 2009-11-21
 *
 */
public class StaffServiceImpl implements StaffService {
	
	private TismStaffDao smStaffDao;
	private TismWorkerDao smWorkerDao;
	
	/* (non-Javadoc)
	 * @see com.firebird.oms.service.sm.impl.StaffService#getStaff(long)
	 */
	public TismStaff getStaff(int staffId) {
		return smStaffDao.get(staffId);
	}
	
	/* (non-Javadoc)
	 * @see com.firebird.oms.service.sm.impl.StaffService#updateStaff(com.firebird.oms.domain.TismStaff)
	 */
	public void updateStaff(TismStaff smStaff) {
		smStaffDao.update(smStaff);
	}
	
	/**
	 * 创建员工信息
	 * @param smStaff
	 */
	public void createStaff(TismStaff smStaff) {
		smStaffDao.create(smStaff);
	}
	
	/**
	 * 创建工号
	 * @param smWorker
	 */
	public void createWorker(TismWorker smWorker) {
		smWorkerDao.create(smWorker);
	}
	
	/**
	 * 更新工号信息
	 * @param smWorker
	 */
	public void updateWorker(TismWorker smWorker) {
		smWorkerDao.update(smWorker);
	}
	
	/**
	 * 获取工号信息
	 * @param loginId
	 * @return
	 */
	public TismWorker getWorker(int loginId) {
		return smWorkerDao.get(loginId);
	}
	
	/**
	 * 根据登录账号获取工号信息
	 * @param loginCode
	 * @return
	 */
	public TismWorker getWorkerByLoginCode(String loginCode) {
		return smWorkerDao.getUniqueBy("loginCode", loginCode);
	}
	
	/**
	 * 查找员工下的所有工号
	 * @param filter
	 * @return
	 */
	public List<TismWorker> findWorkers(Map<String, String> filter) {
		return smWorkerDao.find(filter);
	}
	
	/**
	 * 获取员工信息列表，包括当前登录工号
	 * @param userDetails
	 * @return
	 */
	public List<TismStaff> getStaffs(int staffId) {
		TismStaff currentStaff = this.getStaff(staffId);
		List<TismStaff> childStaff = smStaffDao.findBy("upperStaffId", staffId);
		childStaff.add(currentStaff);
		Collections.sort(childStaff);
		return childStaff;
	}
	
	public void setSmStaffDao(TismStaffDao smStaffDao) {
		this.smStaffDao = smStaffDao;
	}
	public void setSmWorkerDao(TismWorkerDao smWorkerDao) {
		this.smWorkerDao = smWorkerDao;
	}

}
